
package com.makefriends;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.makefriends.activity.BaseActivity;
import com.makefriends.fragment.FifthMyFragment;
import com.makefriends.fragment.FirstFateFragment;
import com.makefriends.fragment.FouthNearbyFragment;
import com.makefriends.fragment.SecondSearchFragment;
import com.makefriends.fragment.ThirdEmailFragment;
import com.makefriends.view.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends BaseActivity implements ViewPager.OnPageChangeListener{

    /**
     * 轮播图
     */
    @Bind(R.id.tabmain_viewPager)
    NoScrollViewPager mViewPager;
    /**
     * 底部缘分
     */
    @Bind(R.id.main_bottom_fate_text)
    TextView mFateText;
    /**
     * 底部查询
     */
    @Bind(R.id.main_bottom_search_text)
    TextView mSearchText;
    /**
     * 底部信箱
     */
    @Bind(R.id.main_bottom_email_text)
    TextView mEmailText;
    /**
     * 底部附近
     */
    @Bind(R.id.main_bottom_nearby_text)
    TextView mEearbyText;

    /**
     * 底部我
     */
    @Bind(R.id.main_bottom_my_text)
    TextView mMyText;

    private List<Fragment> mFragments = new ArrayList<>();

    private FragmentPagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        // 添加Fragment
        mFragments.add(new FirstFateFragment());
        mFragments.add(new SecondSearchFragment());
        mFragments.add(new ThirdEmailFragment());
        mFragments.add(new FouthNearbyFragment());
        mFragments.add(new FifthMyFragment());

        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public int getCount() {
                return mFragments.size();
            }

            @Override
            public Fragment getItem(int arg0) {
                return mFragments.get(arg0);
            }
        };

        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.setOnPageChangeListener(this);
        mViewPager.setNoScroll(true);
        onFateClick(mFateText);
    }

    /**
     * 缘分
     * yuanfen
     * @param view
     */
    @OnClick(R.id.main_bottom_fate_text)
    void onFateClick(View view){
        view.setEnabled(false);
        mSearchText.setEnabled(true);
        mEmailText.setEnabled(true);
        mEearbyText.setEnabled(true);
        mMyText.setEnabled(true);
        mViewPager.setCurrentItem(0);
    }

    /**
     * 搜索
     * @param view
     */
    @OnClick(R.id.main_bottom_search_text)
    void onSearchClick(View view){
        view.setEnabled(false);
        mFateText.setEnabled(true);
        mEmailText.setEnabled(true);
        mEearbyText.setEnabled(true);
        mMyText.setEnabled(true);
        mViewPager.setCurrentItem(1);
    }

    /**
     * 信箱
     * @param view
     */
    @OnClick(R.id.main_bottom_email_text)
    void onEmailClick(View view){
        view.setEnabled(false);
        mSearchText.setEnabled(true);
        mFateText.setEnabled(true);
        mEearbyText.setEnabled(true);
        mMyText.setEnabled(true);
        mViewPager.setCurrentItem(2);
    }

    /**
     * 附近
     * @param view
     */
    @OnClick(R.id.main_bottom_nearby_text)
    void onEearbyClick(View view){
        view.setEnabled(false);
        mSearchText.setEnabled(true);
        mEmailText.setEnabled(true);
        mFateText.setEnabled(true);
        mMyText.setEnabled(true);
        mViewPager.setCurrentItem(3);
    }

    /**
     * 我
     * @param view
     */
    @OnClick(R.id.main_bottom_my_text)
    void onMyClick(View view){
        view.setEnabled(false);
        mSearchText.setEnabled(true);
        mEmailText.setEnabled(true);
        mEearbyText.setEnabled(true);
        mFateText.setEnabled(true);
        mViewPager.setCurrentItem(4);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
